<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@ page pageEncoding="UTF-8" %>
<html>
<head>
    <jsp:include page="/WEB-INF/pages/plugins/include_basepath.jsp"/>
    <jsp:include page="/WEB-INF/pages/plugins/include_head.jsp"/>
</head>
<body role="document">

<div id="mainDiv">
  <div style="width: 98%; margin-left:auto; margin-right:auto; text-align:left;">
<form action="pages/front/password/editPassword" method="post" name="viewEdit" id="viewEdit">
  <table width="98%" class="table table-striped table-hover table-bordered">
    <thead>
      <tr>
        <td colspan="2" align="center">修改密码</td>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td align="left" valign="top">id：</td>
        <td align="left" valign="top"><div class="col-sm-5"><input name="id" type="text" id="id" size="50" value="${sessionScope.name}"  class="form-control"   readonly />
</div></td>
      </tr>
      <tr>
        <td align="left" valign="top">Email：</td>
        <td align="left" valign="top"><div class="col-sm-5"><input name="email" type="text" id="email" size="50" value="${sessionScope.email}"  class="form-control"   readonly="readonly" />
</div></td>
      </tr>
      <tr>
        <td align="left" valign="top">当前密码：</td>
        <td align="left" valign="top"><div class="col-sm-5"><input name="old_password" type="password" id="old_password" size="50" value=""  class="form-control" placeholder="请输入当前密码"/>
        </div><span id="old_password_span" style="color: red"></span></td>
      </tr>
      <tr>
        <td align="left" valign="top">新密码：</td>
        <td align="left" valign="top"><div class="col-sm-5"><input name="new_password" type="password" id="new_password" size="50" value=""  class="form-control" placeholder="请输入新密码"  />
        </div><span id="new_password_span" style="color: red"></span></td>
      </tr>
      <tr>
          <td align="left" valign="top">确认新密码：</td>
          <td align="left" valign="top"><div class="col-sm-5"><input name="confirm_new_password" type="password" id="confirm_new_password" size="50" value=""  class="form-control" placeholder="请输入确认密码"  />
          </div><span id="confirm_new_password_span" style="color: red"></span></td>
      </tr>
      <tr>
        <td colspan="2" align="center"><input type="submit" name="Submit" id="Submit" value="提交" class="btn btn-success" />
          &nbsp;&nbsp;&nbsp;
          <input type="button" name="Submit"  value="返回" onclick="javascript:history.back();" class="btn btn-info" /></td>
      </tr>
    </tbody>
  </table>
</form>
</div>
</div>
</body>
<script type="text/javascript">

$(function(){
	$('#EditPwd').addClass('active');
    $("#old_password").blur(function () {
        oldPasswordFun() ;
    }) ;
    $("#new_password").blur(function () {
        newPasswordFun() ;
    }) ;
    $("#confirm_new_password").blur(function () {
        confirmNewPasswordFun() ;
    }) ;
    $("form").submit(function(e){
        if(! (oldPasswordFun() & newPasswordFun() & confirmNewPasswordFun())) {
            e.preventDefault();
        }
    });
});
function checkPassword(){
    var flag ;
    $.ajax({
        type : 'post',
        url : 'pages/front/password/checkPassword' ,
        async : false ,
        data : {password:$("#old_password").val()} ,
        dataType : 'json' ,
        success : function(data) {
            flag = data ;
        }
    }) ;
    return flag ;
}

function oldPasswordFun() {
    if ($("#old_password").val() == "") {
        $("#old_password_span").text("请输入当前密码") ;
        return false ;
    }else {
        var flag = checkPassword() ;
        if(flag == false) {
            $("#old_password_span").text("当前密码错误") ;
            return false ;
        }else {
            $("#old_password_span").text("") ;
            return true ;
        }
    }
}

function newPasswordFun() {
    if ($("#new_password").val().length < 6) {
        $("#new_password_span").text("密码最少6位") ;
        return false ;
    }else {
        $("#new_password_span").text("") ;
        return true ;
    }
}
function confirmNewPasswordFun() {
    if($("#confirm_new_password").val() == "") {
        $("#confirm_new_password_span").text("请确认新密码") ;
        return false ;
    }else if($("#confirm_new_password").val() != $("#new_password").val()) {
        $("#confirm_new_password_span").text("密码输入错误") ;
        return false ;
    }else {
        $("#confirm_new_password_span").text("")
        return true ;
    }
}

$('#myModal').modal({
	backdrop: "static",
	show: false
})
</script>
</html>